<template>
  <div class="app-container">
    <IntroduceTip :value="4"></IntroduceTip>
    <el-row :gutter="12">
      <el-col :span="4">
        <div class="custom_card">
          <el-table
            v-loading="loadingJob"
            :data="jobList.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
            @row-click="getFinancialList"
            :row-style="rowStyle"
            border
          >
            <el-table-column label="同行名称" align="left" prop="name">
              <template slot="header" slot-scope="scope">
                <el-input
                  v-model="search"
                  size="mini"
                  placeholder="同行名称"/>
              </template>
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
                <span v-if="scope.row.phone">({{ scope.row.phone }})</span>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            layout="prev, pager, next"
            v-show="totalJob > 0"
            :total="totalJob"
            :pager-count="3"
            :page.sync="queryParamsJob.pageNum"
            :limit.sync="queryParamsJob.pageSize"
            @pagination="getSameJobList"
          >
          </pagination>
        </div>
      </el-col>
      <el-col :span="20">
        <div class="custom_card">
          <el-row>
            <el-col :span="24">
              <el-descriptions
                :title="`与 [${sameJob.name}] 已合作${sameJob.days}天`"
                :column="2"
              >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="借入车辆共计"
                  >{{ sameJob.numjr }}次</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="已支付了"
                  >¥{{ sameJob.amountjr }}</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="借出车辆共计"
                  >{{ sameJob.numjc }}次</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="已收入了"
                  >¥{{ sameJob.amountjc }}</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="借出未结算账单共计"
                  >{{ sameJob.noSettjr }}条</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="借出未结算账单共计"
                  >{{ sameJob.noSettjc }}条</el-descriptions-item
                >
                <el-descriptions-item label-class-name="my-descriptions-label"  label="备注">
                  您可使用
                  <el-link
                    type="primary"
                    @click="getSecondedBillsCount(sameJob)"
                    >未结算账单自动对账</el-link
                  >
                  帮您快速结算。自动对账后，可点击
                  <el-link type="primary" @click="historicalTip(sameJob)"
                    >历史对账记录</el-link
                  >
                  重复查询核对。
                </el-descriptions-item>
              </el-descriptions>
            </el-col>
          </el-row>
        </div>
        <div class="custom_card">
          <el-row>
            <el-col :span="24">
              <Tabs
                :list="tabs_list"
                :column="6"
                :minWidth="200"
                :active="queryParams.type"
                @tabs_click="secondedTypeChange"
              ></Tabs>
            </el-col>
            <el-col :span="24" style="margin-top: 20px">
              <el-form
                :model="queryParams"
                ref="queryForm"
                :inline="true"
                v-show="showSearch"
                label-width="68px"
              >
                <el-form-item label="车牌号" prop="carNo">
                  <el-input
                    v-model="queryParams.carNo"
                    placeholder="请输入车牌号"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item label="订单编号" prop="bizNo"   v-if="queryParams.type == 1 || queryParams.type == 3">
                  <el-input
                    v-model="queryParams.bizNo"
                    placeholder="请输入订单编号"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item label="经办人" prop="createBy">
                  <el-select
                    v-model="queryParams.createBy"
                    placeholder="请选择经办人"
                    clearable
                    size="small"
                  >
                    <el-option
                      v-for="user in sysUserList"
                      :key="parseInt(user.userId)"
                      :label="user.userName"
                      :value="parseInt(user.userId)"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="支付方式" prop="payWay">
                  <el-select
                    v-model="queryParams.payWay"
                    placeholder="请选择支付方式"
                    clearable
                    size="small"
                  >
                    <el-option
                      v-for="dict in dict.type.sys_pay_way"
                      v-if="parseInt(dict.value) != 5"
                      :key="parseInt(dict.value)"
                      :label="dict.label"
                      :value="parseInt(dict.value)"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="提交时间" prop="startTime">
                  <el-date-picker
                    clearable
                    size="small"
                    v-model="time"
                    type="daterange"
                    range-separator="至"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                  >
                  <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    :loading="exportLoading"
                    @click="handleExport"
                  >导出</el-button>

                </el-form-item>
                <el-form-item>
                  <el-tooltip placement="top" effect="dark">
                    <div slot="content" style="font-size: 16px">
                      与同行借调车辆产生的借调费用的收支情况。在借调模块操作借调后，费用将同步到此模块
                    </div>
                    <el-button type="text">功能说明&nbsp;<i class="el-icon-warning-outline"></i></el-button>
                  </el-tooltip>
                </el-form-item>
              </el-form>

              <el-table v-loading="loading" :data="financialList" border>
                <el-table-column
                  label="同行"
                  align="center"
                  prop="jobName"
                  min-width="140"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="提交时间"
                  align="center"
                  prop="createTime"
                  min-width="160"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="经办人"
                  align="center"
                  prop="userName"
                  min-width="120"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="车牌号"
                  align="center"
                  prop="carNo"
                  min-width="140"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="订单编号"
                  align="center"
                  prop="orderNo"
                  v-if="queryParams.type == 1 || queryParams.type == 3"
                  min-width="120"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="借调日期"
                  align="center"
                  prop="payableTime"
                  min-width="320"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <span>{{ scope.row.startTime }}</span
                    >-
                    <span>{{ scope.row.endTime }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="借调费用"
                  align="center"
                  prop="payableAmount"
                  min-width="140"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    ¥{{ scope.row.payableAmount }}
                  </template>
                </el-table-column>
                <el-table-column
                  label="结算方式"
                  align="center"
                  prop="settlementWay"
                  min-width="140"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <dict-tag
                      :options="dict.type.settlement_way"
                      :value="scope.row.settlementWay"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="借调状态"
                  align="center"
                  prop="secondedStatus"
                  min-width="140"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <dict-tag
                      :options="dict.type.secondments_state"
                      :value="scope.row.secondedStatus"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="应付时间"
                  align="center"
                  prop="应付时间"
                  min-width="160"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    {{ parseTime(scope.row.payableTime, '{y}-{m}-{d}') }}
                  </template>
                </el-table-column>

                <el-table-column
                  label="财务状态"
                  align="center"
                  prop="settlementStatus"
                  min-width="140"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <dict-tag
                      v-if="queryParams.type == 1 || queryParams.type == 3"
                      :options="dict.type.settlement_status"
                      :value="scope.row.settlementStatus"
                    />
                    <dict-tag
                      v-if="queryParams.type == 2 || queryParams.type == 4"
                      :options="dict.type.settlement_Receive_status"
                      :value="scope.row.settlementStatus"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="支付时间"
                  align="center"
                  prop="payTime"
                  min-width="160"
                  show-overflow-tooltip
                />
                <el-table-column
                  label="支付方式"
                  align="center"
                  prop="payWay"
                  min-width="140"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <dict-tag
                      :options="dict.type.sys_pay_way"
                      :value="scope.row.payWay"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  fixed="left"
                  align="center"
                  width="180"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleEndSeconded(scope.row)"
                    >借调详情
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      v-if="scope.row.settlementStatus != 1"
                      @click="handleDetails(scope.row)"
                      >费用明细</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      v-hasPermi="['bills:seconded:receiveMoney']"
                      v-if="
                        scope.row.settlementStatus != 3 && queryParams.type == 2
                      "
                      @click="handleUpdate(scope.row)"
                      >确认收款</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      v-hasPermi="['bills:seconded:receiveMoney']"
                      v-if="
                        scope.row.settlementStatus != 3 && queryParams.type == 1
                      "
                      @click="handleUpdate(scope.row)"
                      >确认付款</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>

              <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
              />
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>

    <!-- 确认收款 -->
    <el-dialog
      :title="openTitle"
      :visible.sync="open"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="账单时间" prop="payableTime">
              <el-input
                v-model="form.payableTime"
                class="el-input-style"
                style="width: 100%"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账单金额" prop="payableAmount">
              <el-input
                v-model="form.payableTime"
                class="el-input-style"
                style="width: 100%"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付方式" prop="payWay">
              <el-select
                v-model="form.payWay"
                style="width: 100%"
                placeholder="请选择支付方式"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in dict.type.sys_pay_way"
                  v-if="parseInt(dict.value) != 5"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付时间" prop="payTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.payTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择支付时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付金额" prop="payAmount">
              <el-input
                v-model="form.payAmount"
                placeholder="请输入支付金额"
                maxlength="10"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="支付凭证">
              <ImageUpload
                @on-success="costImageSuccess"
                v-model="form.costImage"
                :limit="6"
                @on-remove="costImageRemove"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="submitLoading"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--未结算账单自动对账-->
    <el-dialog
      title="未结算账单自动对账"
      :visible.sync="openNoSett"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-row>
        <el-col :span="24" style="color: #333333; font-size: 18px">
          <div style="margin-left: 10px">
            <span style="color: #1a70ff">{{
              parseTime(secondedBills.currentTime, '{y}-{m}-{d} {h}:{i}:{s}')
            }}</span
            >自动对账完成，<span style="color: red"
              >你需要支付{{ sameJob.name }}借调费用{{
                secondedBills.yf
              }}元，同行需要支付你借调费用¥{{ secondedBills.ys }}元</span
            >
          </div>
          <div style="margin-left: 10px">
            本次自动对账第一条未结算订单数据从
            <span style="color: #1a70ff">{{
              parseTime(secondedBills.startTime, '{y}-{m}-{d} {h}:{i}:{s}')
            }}</span
            >，我借调同行车辆<span style="color: #00c585"
              >{{ secondedBills.startCarNo }}开始</span
            >
          </div>
          <div style="margin-left: 10px">
            最后一次未结算订单数据从<span style="color: #1a70ff">{{
              parseTime(secondedBills.endTime, '{y}-{m}-{d} {h}:{i}:{s}')
            }}</span
            >，我借调同行车辆<span style="color: #00c585">{{
              secondedBills.endCarNo
            }}</span
            >结束
          </div>
          <div style="margin-left: 10px">
            共计对账{{ secondedBills.allBills }}条账单，我借调同行{{
              secondedBills.jr
            }}条，同行借调我{{ secondedBills.jc }}条
            <el-button @click="selectReconciliationRecords"
              >查看详细记录</el-button
            >
            <el-button type="primary" @click="oneClickCheckout"
              >已核对无误，一键清账</el-button
            >
          </div>
        </el-col>
        <el-col :span="24">
          <el-divider></el-divider>
        </el-col>
        <el-col :span="24">
          <el-table
            v-loading="reconciliationLoading"
            :data="reconciliationList"
            border
          >
            <el-table-column
              label="自动对账日期"
              align="center"
              prop="reconciliationTime"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column
              label="对账人"
              align="center"
              prop="userName"
              min-width="140"
              show-overflow-tooltip
            />
            <el-table-column
              label="操作"
              align="center"
              fixed="left"
              width="160"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  @click="selectDetails(scope.row)"
                  >查看详细记录</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="totalBilReconciliation > 0"
            :total="totalBilReconciliation"
            :page.sync="queryParamsBilReconciliation.pageNum"
            :limit.sync="queryParamsBilReconciliation.pageSize"
            @pagination="getSelectBilReconciliationList"
          />
        </el-col>
      </el-row>
    </el-dialog>
    <el-drawer
      title="查看详细记录"
      :visible.sync="drawerFlagReconciliationRecords"
      :direction="directionReconciliationRecords"
      size="50%"
      :before-close="handleReconciliationRecordsClose"
      :modal="false"
    >
      <el-col
        :span="24"
        style="color: #333333; font-size: 18px; margin-left: 5px"
      >
        <div style="margin-left: 10px">
          <span style="color: #1a70ff">{{
            parseTime(secondedBills.currentTime, '{y}-{m}-{d} {h}:{i}:{s}')
          }}</span
          >自动对账完成，<span style="color: red"
            >你需要支付{{ sameJob.name }}借调费用{{
              secondedBills.yf
            }}元，同行需要支付你借调费用¥{{ secondedBills.ys }}元</span
          >
        </div>
        <div style="margin-left: 10px">
          本次自动对账第一条未结算订单数据从
          <span style="color: #1a70ff">{{
            parseTime(secondedBills.startTime, '{y}-{m}-{d} {h}:{i}:{s}')
          }}</span
          >，我借调同行车辆<span style="color: #00c585"
            >{{ secondedBills.startCarNo }}开始</span
          >
        </div>
        <div style="margin-left: 10px">
          最后一次未结算订单数据从<span style="color: #1a70ff">{{
            parseTime(secondedBills.endTime, '{y}-{m}-{d} {h}:{i}:{s}')
          }}</span
          >，我借调同行车辆<span style="color: #00c585">{{
            secondedBills.endCarNo
          }}</span
          >结束
        </div>
        <div style="margin-left: 10px">
          共计对账{{ secondedBills.allBills }}条账单，我借调同行{{
            secondedBills.jr
          }}条，同行借调我{{ secondedBills.jc }}条
        </div>
      </el-col>
      <el-col :span="23" :offset="1" style="margin-top: 10px">
        <div style="display: flex">
          <div
            class="app-app-tab-item"
            :class="{
              'app-app-tab-item-active':
                queryParamsReconciliationRecords.type == 1,
            }"
            @click="secondedRecordsTypeChange(1)"
          >
            <span>借入待付金额</span>
            <span>¥{{ sameJob.noPayjr }}</span>
          </div>
          <div
            class="app-app-tab-item"
            :class="{
              'app-app-tab-item-active':
                queryParamsReconciliationRecords.type == 2,
            }"
            @click="secondedRecordsTypeChange(2)"
          >
            <span>借出待收金额</span>
            <span>¥{{ sameJob.noPayjc }}</span>
          </div>
        </div>
      </el-col>
      <el-col :span="23" :offset="1" style="margin-top: 10px">
        <el-form
          :model="queryParamsReconciliationRecords"
          ref="queryReconciliationRecordsForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="车牌号" prop="carNo">
            <el-input
              v-model="queryParamsReconciliationRecords.carNo"
              placeholder="请输入车牌号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订单编号" prop="bizNo">
            <el-input
              v-model="queryParamsReconciliationRecords.bizNo"
              placeholder="请输入订单编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="经办人" prop="createBy">
            <el-select
              v-model="queryParamsReconciliationRecords.createBy"
              placeholder="请选择经办人"
              clearable
              size="small"
            >
              <el-option
                v-for="user in sysUserList"
                :key="parseInt(user.userId)"
                :label="user.userName"
                :value="parseInt(user.userId)"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="支付方式" prop="payWay">
            <el-select
              v-model="queryParamsReconciliationRecords.payWay"
              placeholder="请选择支付方式"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in dict.type.sys_pay_way"
                v-if="parseInt(dict.value) != 5"
                :key="parseInt(dict.value)"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQueryReconciliationRecords"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="resetQueryReconciliationRecords"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="23" :offset="1">
        <el-table
          v-loading="loadingReconciliationRecordsDrawer"
          :data="ReconciliationRecordsDrawerList"
          border
        >
          <el-table-column
            label="提交时间"
            align="center"
            prop="createTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="经办人"
            align="center"
            prop="userName"
            min-width="140"
            show-overflow-tooltip
          />
          <el-table-column
            label="车牌号"
            align="center"
            prop="carNo"
            min-width="140"
            show-overflow-tooltip
          />
          <el-table-column
            label="订单编号"
            align="center"
            prop="orderNo"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="借调日期"
            align="center"
            prop="payableTime"
            min-width="320"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span>{{ scope.row.startTime }}</span
              >-
              <span>{{ scope.row.endTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="借调费用"
            align="center"
            prop="payableAmount"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              ¥{{ scope.row.payableAmount }}
            </template>
          </el-table-column>
          <el-table-column
            label="结算方式"
            align="center"
            prop="settlementWay"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.settlement_way"
                :value="scope.row.settlementWay"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="借调状态"
            align="center"
            prop="secondedStatus"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.secondments_state"
                :value="scope.row.secondedStatus"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="应付时间"
            align="center"
            prop="payableTime"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ parseTime(scope.row.payableTime, '{y}-{m}-{d}') }}
            </template>
          </el-table-column>

          <el-table-column
            label="财务状态"
            align="center"
            prop="settlementStatus"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                v-if="queryParams.type == 1 || queryParams.type == 3"
                :options="dict.type.settlement_status"
                :value="scope.row.settlementStatus"
              />
              <dict-tag
                v-if="queryParams.type == 2 || queryParams.type == 4"
                :options="dict.type.settlement_Receive_status"
                :value="scope.row.settlementStatus"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="支付时间"
            align="center"
            prop="payTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="支付方式"
            align="center"
            prop="payWay"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_pay_way"
                :value="scope.row.payWay"
              />
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="totalReconciliationRecords > 0"
          :total="totalReconciliationRecords"
          :page.sync="queryParamsReconciliationRecords.pageNum"
          :limit.sync="queryParamsReconciliationRecords.pageSize"
          @pagination="getReconciliationRecordsList"
        />
      </el-col>
    </el-drawer>
    <el-dialog
      title="系统提示"
      :visible.sync="openTip"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <div style="margin-left: 10px">
        一键清账确认后，<span style="color: #1a70ff"
          >{{ parseTime(secondedBills.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }} -
          {{
            parseTime(secondedBills.endTime, '{y}-{m}-{d} {h}:{i}:{s}')
          }}</span
        >范围内的待付款和待收款全部变为已收款和已付款，无需在手动处理每条数据
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelTip">取消</el-button>
        <el-button type="primary" @click="submitTipForm">确定清账</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="系统提示"
      :visible.sync="openDoneTip"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form label-width="125px" label-position="right" class="scheduled">
        <div style="padding: 20px 50px 0px 50px; text-align: center">
          <el-image
            class="preview"
            :src="overPng"
            fit="contain"
            style="height: 80px; width: 80px"
          ></el-image>
        </div>
        <div style="text-align: center; font-size: 20px; color: #027db4">
          清账完成
        </div>
        <div style="text-align: center; margin-top: 20px">
          <el-button @click="cancelDoneTip">返回</el-button>
        </div>
      </el-form>
    </el-dialog>
    <el-dialog
      title="系统提示"
      :visible.sync="xianshiFlag"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form label-width="125px" label-position="right" class="scheduled">
        <el-row type="flex" justify="center">
          <el-col :span="6">
            <div style="padding: 20px 50px 0px 50px">
              <el-image class="preview" :src="overPng" fit="contain"></el-image>
            </div>
            <div style="text-align: center; font-size: 16px; color: #027db4">
              部分清账完成
            </div>
          </el-col>
          <el-col :span="16" style="margin-top: 16px;">
            <el-form-item>{{ xianshi }}</el-form-item>
          </el-col>
        </el-row>
        <div style="margin-top: 16px; text-align: center">
          <el-button @click="cancelxianTip">返回</el-button>
          <el-button @click="payNow">立即支付</el-button>
          <el-button @click="cancelxianTip">暂时挂起</el-button>
        </div>
      </el-form>
    </el-dialog>
    <el-dialog
      title="历史对账记录"
      :visible.sync="historicalFlag"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-row>
        <el-col :span="24">
          <el-table v-loading="historicalLoading" :data="historicalList" border>
            <el-table-column
              label="自动对账日期"
              align="center"
              prop="reconciliationTime"
              min-width="160"
              show-overflow-tooltip
            />
            <el-table-column
              label="对账人"
              align="center"
              prop="userName"
              min-width="140"
              show-overflow-tooltip
            />
            <el-table-column
              label="操作"
              align="center"
              fixed="left"
              class-name="small-padding fixed-width"
              width="140"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  @click="selectDetails(scope.row)"
                  >查看详细记录</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="totalHistorical > 0"
            :total="totalHistorical"
            :page.sync="queryParamsHistorical.pageNum"
            :limit.sync="queryParamsHistorical.pageSize"
            @pagination="getSelectHistoricalList"
          />
        </el-col>
        <!--        <el-col :span="24">
          <div style="text-align: end"><el-button @click="canceHistoricalTip">返回</el-button></div>
        </el-col>-->
      </el-row>
    </el-dialog>
    <!--对账单明细-->
    <el-drawer
      title="查看对账记录"
      :visible.sync="drawerFlagDetails"
      :direction="directionDetails"
      size="50%"
      :before-close="handleDetailsClose"
      :modal="false"
    >
      <div class="table-padding">
        <el-table
          v-loading="loadingDetailsDrawer"
          :data="DetailsDrawerList"
          border
        >
          <el-table-column
            label="提交时间"
            align="center"
            prop="createTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="经办人"
            align="center"
            prop="userName"
            min-width="140"
            show-overflow-tooltip
          />
          <el-table-column
            label="车牌号"
            align="center"
            prop="carNo"
            min-width="140"
            show-overflow-tooltip
          />
          <el-table-column
            label="订单编号"
            align="center"
            prop="orderNo"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="借调日期"
            align="center"
            prop="payableTime"
            min-width="320"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span>{{ scope.row.startTime }}</span
              >-
              <span>{{ scope.row.endTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="借调费用"
            align="center"
            prop="payableAmount"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              ¥{{ scope.row.payableAmount }}
            </template>
          </el-table-column>
          <el-table-column
            label="对账费用"
            align="center"
            prop="payableAmount"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope"> ¥{{ scope.row.amount }} </template>
          </el-table-column>
          <el-table-column
            label="结算方式"
            align="center"
            prop="settlementWay"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.settlement_way"
                :value="scope.row.settlementWay"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="借调状态"
            align="center"
            prop="secondedStatus"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.secondments_state"
                :value="scope.row.secondedStatus"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="应付时间"
            align="center"
            prop="payableTime"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ parseTime(scope.row.payableTime, '{y}-{m}-{d}') }}
            </template>
          </el-table-column>

          <el-table-column
            label="财务状态"
            align="center"
            prop="settlementStatus"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.settlement_status"
                :value="scope.row.settlementStatus"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="支付时间"
            align="center"
            prop="payTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            label="支付方式"
            align="center"
            prop="payWay"
            min-width="140"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_pay_way"
                :value="scope.row.payWay"
              />
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="totalDetails > 0"
          :total="totalDetails"
          :page.sync="queryParamsDetails.pageNum"
          :limit.sync="queryParamsDetails.pageSize"
          @pagination="getDetailsList"
        />
      </div>
    </el-drawer>
    <!--费用明细-->
    <el-dialog title="费用明细" :visible.sync="openDetails" append-to-body>
      <el-row>
        <el-col :span="24">
          <el-descriptions
            :column="2"
            border
            :labelStyle="{ width: '100px' }"
            :contentStyle="{ width: '300px' }"
          >
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">业务类型</template>
              <dict-tag
                :options="dict.type.pay_biz_type"
                :value="formDetails.bizType"
              />
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">账单类型</template>
              <dict-tag
                :options="dict.type.bill_type"
                :value="formDetails.billType"
              />
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">应付时间</template>
              {{
                parseTime(formDetails.payableTime, '{y}-{m}-{d} {h}:{i}:{s}')
              }}
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">应付金额</template>
              {{ formDetails.payableAmount }}
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">支付时间</template>
              {{ parseTime(formDetails.payTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">支付金额</template>
              {{ formDetails.payAmount }}
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">财务状态</template>
              <dict-tag
                v-if="formDetails.billType == 1"
                :options="dict.type.settlement_Receive_status"
                :value="formDetails.settlementStatus"
              />
              <dict-tag
                v-if="formDetails.billType == 2"
                :options="dict.type.settlement_status"
                :value="formDetails.settlementStatus"
              />
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label" >
              <template slot="label">支付方式</template>
              <dict-tag
                :options="dict.type.sys_pay_way"
                :value="formDetails.payWay"
              />
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label"  :span="2">
              <template slot="label">备注</template>
              {{ formDetails.remark }}
            </el-descriptions-item>
            <el-descriptions-item label-class-name="my-descriptions-label"  :span="2">
              <template slot="label">支付凭证</template>
              <el-image
                v-for="(item, index) in formDetails.urlList"
                :key="index"
                :src="getImgUrl(item)"
                :preview-src-list="[getImgUrl(item)]"
                style="width: 20%; margin-right: 15px"
                fit="contain"
              ></el-image>
            </el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDetails">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 详情 -->
    <el-dialog title="借调详情" :visible.sync="openShow" append-to-body width="900px" >
      <el-form ref="formShow" :model="formShow" label-width="110px">
        <el-row>
          <MmvTitle title="借调信息"></MmvTitle>
          <el-col :span="24" class="table-padding">
            <el-descriptions  :column="2"  border :labelStyle="{ width: '140px' }" >
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">订单号</template>
                {{ formShow.orderNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">车牌号</template>
                {{ formShow.carNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">车架号</template>
                {{ formShow.vinNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调类型</template>
                <dict-tag :options="dict.type.seconded_type" :value="formShow.secondedType"/>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">品牌/车系/车型</template>
                {{ formShow.modelName }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">租赁时间</template>
                {{ formShow.time }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调同行</template>
                {{ formShow.sameJobName }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调开始日期</template>
                {{ formShow.startTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">预约借调结束日期</template>
                {{ formShow.estimateEndTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">预约借调天数</template>
                {{ formShow.estimateDay }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">实际结束日期</template>
                {{ formShow.actualEndTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">实际借调天数</template>
                {{ formShow.actualDay }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">借调单价</template>
                {{ formShow.secondedUnitPrice }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">借调费用</template>
                {{ formShow.totalRent }}
              </el-descriptions-item>
              <el-descriptions-item v-if="formShow.secondedType==2&&formShow.carSource==6&&formShow.secondedStatus == 2" label-class-name="my-descriptions-label">
                <template slot="label">托管费用</template>
                {{ formShow.hostingFees }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">结算方式</template>
                <el-radio-group v-model="formShow.settlementWay" size="medium">
                  <el-radio
                    v-for="dict in dict.type.settlement_way"
                    :label="parseInt(dict.value)"
                    disabled="disabled"
                    :value="parseInt(dict.value)"
                    :key="parseInt(dict.value)"
                    v-if="dict.value == formShow.settlementWay"
                  >{{ dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" span="2">
                <template slot="label">车辆初始图片</template>
                <template v-for="item in formShow.initialPicture">
                  <el-image :key="item" :src="item|mmvImageUrl" :preview-src-list="[$mmvImageUrl(item)]" class="mmv-image" fit="contain"></el-image>
                </template>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调备注</template>
                {{ formShow.remark }}
              </el-descriptions-item>

              <el-descriptions-item label-class-name="my-descriptions-label" span="2" v-if="formShow.secondedStatus == 2">
                <template slot="label">借调结束图片</template>
                <template v-for="item in formShow.endPicture">
                  <el-image :key="item" :src="item|mmvImageUrl" :preview-src-list="[$mmvImageUrl(item)]" class="mmv-image" fit="contain"></el-image>
                </template>
              </el-descriptions-item>

              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">结束借调备注</template>
                {{ formShow.endRemark }}
              </el-descriptions-item>
            </el-descriptions>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openShow = false" >关  闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  secondedBillsList,
  getFinancial,
  secondedBillsCount,
  selectBilReconciliationList,
  reconciliationDetails,
  addFinancial,
  receiveMoney,
  cleanUpBills,
  payNow,
  exportSecondedFinancial,
} from '@/api/bills/financial'

import { userlist } from '@/api/system/user'
import { jobCountlist,jobCountlist1 } from '@/api/seconded/job'
import Tabs from '@/components/custom/tabs.vue'
import {getSeconded} from "@/api/seconded/seconded";
import MmvTitle from "@/components/MmvUI/MmvTitle";
export default {
  name: 'Seconded',
  dicts: [
    'sys_pay_way',
    'settlement_way',
    'seconded_type',
    'settlement_Receive_status',
    'secondments_state',
    'settlement_status',
    'pay_biz_type',
    'bill_type',
  ],
  components: {
    Tabs,
    MmvTitle,
  },
  data() {
    return {

      formShow: {
        settlementWay: null,
      },
      openShow:false,
      showTip:true,
      overPng: require('@/assets/images/over.png'),
      // 遮罩层
      loading: true,
      historicalFlag: false,
      reconciliationLoading: false,
      historicalList: [],
      historicalLoading: false,
      totalHistorical: 0,
      totalCount:0,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      submitLoading: false,
      // 非单个禁用
      single: true,
      openTip: false,
      openDoneTip: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      maxAmount: null,
      openTitle:'财务收款',
      // 总条数
      total: 0,
      // 财务账单表格数据
      financialList: [],
      sysUserList: [],
      jobList: [],
      search:'',
      loadingJob: false,
      totalJob: 0,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openNoSett: false,
      xianshi: null,
      xianshiFlag: false,
      payNowFlag: false,
      urlPayForm: {},
      queryParamsJob: {
        pageNum: 1,
        pageSize: 10,
      },
      queryParamsBilReconciliation: {
        pageNum: 1,
        pageSize: 10,
        carNo: null,
        type: 1,
        jobId: null,
        bizNo: null,
        createBy: null,
      },
      queryParamsHistorical: {
        pageNum: 1,
        pageSize: 10,
        type: 1,
        jobId: null,
      },
      sameJob: {
        id: null,
        name: '--',
        days: 0,
        numjr: 0,
        numjc: 0,
        amountjr: 0,
        amountjc: 0,
        noSettjr: 0,
        noSettjc: 0,
        noPayjr: 0,
        noPayjc: 0,
        payjr: 0,
        payjc: 0,
      },
      tabs_list: [
        { key: '1', name: '借入待付金额', count: '￥0' },
        { key: '2', name: '借出待收金额', count: '￥0' },
        { key: '3', name: '历史借入已付金额', count: '￥0' },
        { key: '4', name: '历史借出已收金额', count: '￥0' },
      ],
      secondedBills: {
        currentTime: null,
        ys: 0,
        yf: 0,
        jc: 0,
        jr: 0,
        allBills: 0,
        startTime: null,
        endTime: null,
        startCarNo: null,
        endCarNo: null,
      },
      reconciliationList: [],
      time: [],
      totalBilReconciliation: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bizType: null,
        bizNo: null,
        billType: null,
        payableTime: null,
        payableAmount: null,
        payTime: null,
        payAmount: null,
        settlementStatus: null,
        payWay: null,
        deptId: null,
        tenantId: null,
        createBy: null,
        carNo: null,
        type: 1,
        jobId: null,
      },
      drawerFlagReconciliationRecords: false,
      loadingReconciliationRecordsDrawer: false,
      directionReconciliationRecords: 'rtl',
      ReconciliationRecordsDrawerList: [],
      totalReconciliationRecords: 0,

      queryParamsReconciliationRecords: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payWay: [
          { required: true, message: '支付方式不能为空', trigger: 'blur' },
        ],
        payTime: [
          { required: true, message: '支付时间不能为空', trigger: 'blur' },
        ],
        payAmount: [
          { required: true, message: '支出费用不能为空', trigger: 'change' },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2})))$/,
            message: '费用输入有误',
            trigger: 'blur',
          },
        ],
      },
      urlPay: null,
      /*对账单明细详情*/
      drawerFlagDetails: false,
      loadingDetailsDrawer: false,
      directionDetails: 'rtl',
      DetailsDrawerList: [],
      totalDetails: 0,

      queryParamsDetails: {
        pageNum: 1,
        pageSize: 10,
        id: null,
      },
      openDetails: false,
      formDetails: {},
      currentRowId: 1,
    }
  },
  created() {
    //this.getList();
    this.getUserList()
    this.getSameJobList()
  },
  activated() {
    this.getList()
  },
  methods: {
    handleEndSeconded(row) {
      const id = row.secondedId
      getSeconded(id).then((response) => {
        this.formShow = response.data
        this.formShow.time = response.data.rentalStartTime + ' 至 ' + response.data.rentalEndTime
        this.openShow = true
      })
    },
    closeTip(){
      this.showTip = false;
    },
    rowStyle({row, rowIndex}) {
      if (this.currentRowId === row.id) {
        // 此处返回选中行的样式对象，按需设置
        return {
          color: '#1890ff',
        }
      }
    },
    /*对账单明细详情*/
    /*费用明细*/
    handleDetails(row) {
      this.openDetails = true
      getFinancial(row.id).then((response) => {
        this.formDetails = response.data
      })
    },
    cancelDetails() {
      this.openDetails = false
    },
    handleDetailsClose(done) {
      done()
    },
    selectDetails(val) {
      this.drawerFlagDetails = true
      this.queryParamsDetails.id = val.id
      this.getDetailsList()
    },
    /** 查询对账单明细详情列表 */
    getDetailsList() {
      this.loadingDrawer = true
      reconciliationDetails(this.queryParamsDetails).then((response) => {
        this.DetailsDrawerList = response.rows
        this.totalDetails = response.total
        this.loadingDrawer = false
      })
    },
    /*历史对账记录*/
    canceHistoricalTip() {
      this.historicalFlag = false
    },
    historicalTip(val) {
      this.historicalFlag = true
      this.queryParamsHistorical.pageNum = 1
      this.getSelectHistoricalList()
    },
    //历史对账记录--列表
    getSelectHistoricalList() {
      this.queryParamsHistorical.id = this.sameJob.id
      this.reconciliationLoading = true
      selectBilReconciliationList(this.queryParamsHistorical).then(
        (response) => {
          this.historicalList = response.rows
          this.totalHistorical = response.total
          this.reconciliationLoading = false
        }
      )
    },
    //一键对冲
    oneClickCheckout() {
      this.openTip = true
    },
    handleReconciliationRecordsClose(done) {
      done()
    },
    selectReconciliationRecords() {
      this.drawerFlagReconciliationRecords = true
      this.queryParamsReconciliationRecords.type = 1
      this.getReconciliationRecordsList()
    },
    handleQueryReconciliationRecords() {
      this.queryParamsReconciliationRecords.pageNum = 1
      this.queryParamsReconciliationRecords.type = 1
      this.getReconciliationRecordsList()
    },
    secondedRecordsTypeChange(val) {
      this.queryParamsReconciliationRecords.type = val
      this.getReconciliationRecordsList()
    },
    /** 查询未结算记录列表 */
    getReconciliationRecordsList() {
      this.queryParamsReconciliationRecords.jobId = this.sameJob.id
      this.loadingReconciliationRecordsDrawer = true
      secondedBillsList(this.queryParamsReconciliationRecords).then(
        (response) => {
          this.ReconciliationRecordsDrawerList = response.rows
          this.totalReconciliationRecords = response.total
          this.loadingReconciliationRecordsDrawer = false
        }
      )
    },
    /** 重置按钮操作 */
    resetQueryReconciliationRecords() {
      this.resetForm('queryReconciliationRecordsForm')
      this.handleQueryReconciliationRecords()
    },
    //自动未结算账单
    getSecondedBillsCount(item) {
      if (this.sameJob.noSettjr == 0) {
        this.$message.error('暂无借入记录，无法进行对账')
        return
      }
      if (this.sameJob.noSettjc == 0) {
        this.$message.error('暂无借出记录，无法进行对账')
        return
      }
      this.openNoSett = true
      secondedBillsCount(item).then((response) => {
        this.secondedBills = response.data
        this.queryParamsBilReconciliation.id = item.id
        this.getSelectBilReconciliationList()
      })
    },
    //历史对账记录--对账
    getSelectBilReconciliationList() {
      this.reconciliationLoading = true
      selectBilReconciliationList(this.queryParamsBilReconciliation).then(
        (response) => {
          this.reconciliationList = response.rows
          this.totalBilReconciliation = response.total
          this.reconciliationLoading = false
        }
      )
    },
    // 删除图片
    costImageRemove(file) {
      this.form.costImage = null
    },
    // 上传成功回调
    costImageSuccess(res) {
      this.form.costImage = res.fileName
      this.$refs['form'].validateField('costImage')
    },
    // 删除图片--凭证
    urlPayRemove(file) {
      this.urlPayForm.urlPay = null
    },
    // 上传成功回调--凭证
    urlPaySuccess(res) {
      this.urlPayForm.urlPay = res.fileName
      this.$refs['urlPayForm'].validateField('urlPay')
    },
    secondedTypeChange(val) {
      this.resetQuery()
      this.queryParams.type = val
      this.getList()
    },
    getFinancialList(val) {
      this.sameJob = val;
      if(this.sameJob) {
        this.tabs_list = [
          {key: '1', name: '借入待付金额', count: '￥' + val.noPayjr},
          {key: '2', name: '借出待收金额', count: '￥' + val.noPayjc},
          {key: '3', name: '历史借入已付金额', count: '￥' + val.payjr},
          {key: '4', name: '历史借出已收金额', count: '￥' + val.payjc},
        ]
        this.queryParams.type = 1
        this.queryParams.jobId = val.id
        this.getList()
        this.currentRowId = val.id
      }
    },
    getSameJobList1() {
      jobCountlist1(this.queryParams).then((response) => {
        let carBill1 = response.data;
        this.tabs_list = [
          {key: '1', name: '借入待付金额', count: '￥' + this.sameJob.noPayjr},
          {key: '2', name: '借出待收金额', count: '￥' + this.sameJob.noPayjc},
          {key: '3', name: '历史借入已付金额', count: '￥' + this.sameJob.payjr},
          {key: '4', name: '历史借出已收金额', count: '￥' + this.sameJob.payjc},
        ]
        if(carBill1==null){
         this.tabs_list.forEach(i=>{
           if(parseInt(i.key)==parseInt(this.queryParams.type)){
             switch (parseInt(i.key)) {
               case 1:
                 i.count = '￥0';
                 break
               case 2:
                 i.count = '￥0';
                 break
               case 3:
                 i.count = '￥0';
                 break
               case 4:
                 i.count = '￥0';
                 break
             }
           }

         })
        }else{
          this.tabs_list.forEach(i=>{
            if(parseInt(i.key)==parseInt(this.queryParams.type)){
            switch (parseInt(i.key)) {
              case 1:
                i.count = '￥' + carBill1.noPayjr;
                break
              case 2:
                i.count = '￥' +  carBill1.noPayjc;
                break
              case 3:
                i.count = '￥' + carBill1.payjr;
                break
              case 4:
                i.count = '￥' +  carBill1.payjc;
                break
            } }
          })

        }

      })
    },
    /** 查询借调同行列表 */
    getSameJobList() {
      this.loadingJob = true
      jobCountlist(this.queryParamsJob).then((response) => {
        if (response.rows == null || response.rows.length == 0) {
          this.sameJob = {
            name: '--',
            days: 0,
            numjr: 0,
            numjc: 0,
            amountjr: 0,
            amountjc: 0,
            noSettjr: 0,
            noSettjc: 0,
            noPayjr: 0,
            noPayjc: 0,
            payjr: 0,
            payjc: 0,
          }
          this.financialList = []
          this.loading = false
          this.loadingJob = false
        } else {
          this.jobList = response.rows
          this.totalJob = response.total
          if (this.jobList) {
            if (this.sameJob&&this.sameJob.id) {
              let filterElement = this.jobList.filter((i) => i.id == this.sameJob.id)[0];
              if(filterElement){
                this.getFinancialList(
                  filterElement
                )
              }

            } else {
              this.getFinancialList(this.jobList[0])
            }
          } else {
            this.financialList = []
            this.loading = false
          }
          this.loadingJob = false
        }

        this.loadingJob = false
      })
    },
    getUserList() {
      userlist({}).then((response) => {
        this.sysUserList = response.data
      })
    },
    /** 查询财务账单列表 */
    getList() {
      this.loading = true
      secondedBillsList(this.queryParams).then((response) => {
        this.financialList = response.rows
        this.total = response.total
        this.loading = false
        this.getSameJobList1();
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    cancelTip() {
      this.openTip = false
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bizType: null,
        jobName: null,
        bizNo: null,
        billType: null,
        payableTime: null,
        payableAmount: null,
        payTime: null,
        payAmount: null,
        settlementStatus: 0,
        payWay: null,
        deptId: null,
        tenantId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        costImage: null,
        urlList: [],
      }
      this.resetForm('form')
    },
    //一键清账
    submitTipForm() {
      cleanUpBills(this.sameJob).then((response) => {
        if (response.code === 200) {
          let amount = parseFloat(response.data)
          this.openTip = false
          if (amount === 0) {
            this.openDoneTip = true
          } else if (amount > 0) {
            this.xianshi = '需补缴' + this.sameJob.name + '¥' + amount + '元'
            this.xianshiFlag = true
          } else {
            this.xianshi =
              '剩余你需要支付' +
              this.sameJob.name +
              '同行借调费用¥' +
              -amount +
              '元'
            this.xianshiFlag = true
          }
        } else {
          this.$message.error(response.msg)
        }
      })
    },
    //清账完成
    cancelDoneTip() {
      this.getSameJobList()
      this.openNoSett = false
      this.openDoneTip = false
    },
    //挂起
    cancelxianTip() {
      this.getSameJobList()
      this.openNoSett = false
      this.xianshiFlag = false
    },
    //取消上传支付凭证
    cancelurlPayTip() {
      this.payNowFlag = false
      this.openNoSett = false
    },
    successPay() {
      this.urlPayForm = {
        id: this.sameJob.id,
      }
    },
    //立即支付
    payNow() {
      //this.payNowFlag=true;
      this.$modal
        .confirm('是否进行立即支付？')
        .then(() => {
          this.urlPayForm = {
            id: this.sameJob.id,
          }
          payNow(this.urlPayForm).then((response) => {
            this.$modal.msgSuccess('支付成攻')
            this.xianshiFlag = false
            this.openNoSett = false
            this.getSameJobList()
          })
        })
        .then((response) => {
          this.$download.name(response.msg)
        })
        .catch(() => {
        })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.time) {
       /* this.queryParams.startTime = this.time[0]
        this.queryParams.endTime = this.time[1]*/
        this.queryParams.startTime = this.parseTime(
          this.time[0],
          '{y}-{m}-{d} {h}:{i}:{s}'
        )
        this.queryParams.endTime = this.parseTime(
          this.time[1],
          '{y}-{m}-{d} {h}:{i}:{s}'
        )
      } else {
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      }
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.time = []
      this.queryParams.bizNo=null
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加财务账单'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getFinancial(id).then((response) => {
        this.form = response.data
        if (this.form.payAmount == null) {
          this.form.payAmount = 0
        }
        this.form.payAmount = this.form.payableAmount - this.form.payAmount
        this.form.payAmount = this.form.payAmount < 0 ? 0 : this.form.payAmount
        this.maxAmount = this.form.payAmount
        this.form.payAmount = parseFloat(this.form.payAmount).toFixed(2)
        this.form.payTime = this.parseTime(
          new Date(),
          '{y}-{m}-{d} {h}:{i}:{s}'
        )
        this.form.urlList = []
        console.log(this.maxAmount)
        console.log(this.form)
        this.open = true
        if (this.queryParams.type == 2) {
          this.openTitle = '财务收款'
        }
        if (this.queryParams.type == 1) {
          this.openTitle = '财务付款'
        }
        this.title = '收款'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.submitLoading = true
          if (this.form.costImage) {
            this.form.urlList = this.form.costImage.split(',')
          }
          if (this.form.id != null) {
            receiveMoney(this.form)
              .then((response) => {
                this.$modal.msgSuccess('收款成功')
                this.open = false
                // this.getSameJobList();
                jobCountlist(this.queryParamsJob).then((response) => {
                  if (response.rows == null || response.rows.length == 0) {
                    this.sameJob = {
                      name: '--',
                      days: 0,
                      numjr: 0,
                      numjc: 0,
                      amountjr: 0,
                      amountjc: 0,
                      noSettjr: 0,
                      noSettjc: 0,
                    }
                  } else {
                    this.jobList = response.rows
                    this.totalJob = response.total
                    this.jobList.forEach((i) => {
                      if (i.id == this.sameJob.id) {
                        this.sameJob = i
                        this.getFinancialList(i)
                      }
                    })
                  }
                })
                this.submitLoading = false
              })
              .catch((item) => {
                this.submitLoading = false
              })
          } else {
            addFinancial(this.form)
              .then((response) => {
                this.$modal.msgSuccess('新增成功')
                this.open = false
                this.getSameJobList()
                this.submitLoading = false
              })
              .catch((item) => {
                this.submitLoading = false
              })
          }
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal
        .confirm('是否确认导出所有财务账单数据项？')
        .then(() => {
          this.exportLoading = true
          return exportSecondedFinancial(queryParams)
        })
        .then((response) => {
          this.$download.name(response.msg)
          this.exportLoading = false
        })
        .catch(() => {
        })
    },
  }
}
</script>
<style scoped="scoped">
/* .button1 {
    color: #efe8e8;
}
.button2 {
    color: #137ad9;
} */
.scheduled .el-form-item {
  margin-bottom: 0 !important;
}
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.mf-title {
  /* font-size: 18px; */
  font-weight: bold;
}
</style>

